#include "CombatHandler.h"

CombatHandler::CombatHandler() {
	vector<MenuItem> items;
	items.push_back(MenuItem("Attack"));
	items.push_back(MenuItem("Defend"));
	items.push_back(MenuItem("Run"));
	Menu::pushMenuStack(new Menu(0, 0, items, SelectFunctionData(CombatHandler::selectMainAction)));
}

CombatHandler::~CombatHandler() {
	Menu::clearMenuStack();
}

void CombatHandler::selectMainAction(int actionId) {
	switch(actionId) {
	case 0:
		int x = Menu::getTopMenu()->getX() + Menu::getTopMenu()->getWidth();
		vector<MenuItem> enemies;
		enemies.push_back(MenuItem("Goblin"));
		enemies.push_back(MenuItem("Skeleton"));
		enemies.push_back(MenuItem("Kobold"));
		Menu::pushMenuStack(new Menu(x, 0, enemies, SelectFunctionData(CombatHandler::attack)));
		break;
	case 1:
		Menu::clearMenuStack();
		break;
	case 2:
		Menu::clearMenuStack();
		break;
	}
}

void CombatHandler::attack(int enemyId) {
	Menu::clearMenuStack();
}

void CombatHandler::draw() {
	Menu::drawMenuStack();
}

void CombatHandler::update(float dTime) {
	for (vector<ActionData*>::iterator iter = activeActions.begin();
			iter < activeActions.end(); iter++) {
		ActionData* current = *iter;
		current->timeLeft -= dTime;
		if (current->timeLeft <= 0) {
			executeAction(current);
			iter = activeActions.erase(iter);
			delete current;
		}
	}
}

void CombatHandler::handleEvent(SDL_Event* event) {
	Menu* activeMenu = Menu::getTopMenu();
	if(activeMenu) {
		activeMenu->handleEvent(event);
	}
}

void executeAction(ActionData* actionData) {
	switch (actionData->actionType) {
	case actionType::ATTACK :
		break;
	case actionType::ITEM :
		break;
	case actionType::SPELL :
		break;
	case actionType::DEFEND :
		break;
	case actionType::TRANSFORM :
		break;
	case actionType::MOVE :
		break;
	case actionType::WAIT :
		break;
	case default :
		break;
	}
}
